package com.calendar.api.controller;

import com.calendar.api.model.ApiResponse;
import com.calendar.api.model.dto.UserDTO;
import com.calendar.api.security.JwtTokenProvider;
import com.calendar.api.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/users")
@Api(tags = "用户管理")
public class UserController {

    private final UserService userService;
    private final JwtTokenProvider jwtTokenProvider;

    @Autowired
    public UserController(UserService userService, JwtTokenProvider jwtTokenProvider) {
        this.userService = userService;
        this.jwtTokenProvider = jwtTokenProvider;
    }

    @GetMapping("/me")
    @ApiOperation("获取当前用户信息")
    public ApiResponse<UserDTO> getCurrentUser(HttpServletRequest request) {
        String token = jwtTokenProvider.resolveToken(request);
        Long userId = jwtTokenProvider.getUserId(token);
        return ApiResponse.success(userService.getUserById(userId));
    }
} 